{include file='admin/header.html'}

<form class="layui-form" style="margin: 15px 15px 0 0;">
    <!-- 表单字段 -->
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.from}</label>
        <div
            class="layui-input-{if isset($smarty.request.send_type) && $smarty.request.send_type == 'test'}inline{else}block{/if}">
            <input type="email" name="from"
                value="{if isset($smarty.request.send_type) && $smarty.request.send_type == 'test'}{$smtp_email}{/if}"
                placeholder="{$tran.input_send_email}" {if isset($smarty.request.send_type) && $smarty.request.send_type=='test'} readonly{/if}
                required lay-verify="required" autocomplete="off" class="layui-input">
        </div>
        {if isset($smarty.request.send_type) && $smarty.request.send_type == 'test'}
        <div class="layui-form-mid layui-word-aux">{$tran.cannot_modify} {if !$smtp_email}({$tran.please_set}){/if}</div>
        {/if}
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.to}</label>
        <div
            class="layui-input-{if isset($smarty.request.send_type) && $smarty.request.send_type == 'test'}block{else}inline{/if}">
            <input type="email" name="to"
                value="{if !isset($smarty.request.send_type) || $smarty.request.send_type != 'test'}hallelujahlord@foxmail.com{/if}"
                placeholder="{$tran.input_to_email}" {if !isset($smarty.request.send_type) || $smarty.request.send_type != 'test'} readonly{/if}
                required lay-verify="required" autocomplete="off" class="layui-input">
        </div>
        {if !isset($smarty.request.send_type) || $smarty.request.send_type != 'test'}
        <div class="layui-form-mid layui-word-aux">{$tran.cannot_modify}</div>
        {/if}
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.title}</label>
        <div class="layui-input-block">
            <input type="text" name="title" value="" placeholder="{$tran.input_title}" autocomplete="off" required lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">{$tran.content}</label>
        <div class="layui-input-block">
            <textarea name="content" placeholder="{$tran.input_content}" id="lay-content" lay-verify="lay-content" required lay-verify="required" autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <div class="layui-inline">
                <input type="hidden" name="id" value="{$row.id}">
                {if isset($smarty.request.send_type) && $smarty.request.send_type == 'test'}<input type="hidden" name="send_type" value="test">{/if}
                <button class="layui-btn" lay-submit lay-filter="sendmail"><i class="layui-icon layui-icon-release"></i>{$tran.sendmail}</button>
            </div>
            <div class="layui-inline">
                <div class="layui-form-mid" id="sendmail-tip"></div>
            </div>
        </div>
    </div>
</form>

<script>
    // JS
    layui.use(['form', 'upload', 'layedit'], function () {
        var form = layui.form,
            upload = layui.upload,
            layedit = layui.layedit,
            $ = layui.jquery;

        // layedit富文本
        var lay_content = layedit.build('lay-content', {
            tool: [
                'strong', //加粗
                'italic', //斜体
                'underline', //下划线
                'del', //删除线
                '|', //分割线
                'left', //左对齐
                'center', //居中对齐
                'right', //右对齐
                '|', //分割线
                'link', //超链接
                'unlink', //清除链接
            ]
        });

        // 监听提交
        form.on("submit(sendmail)", function (data) {
            $('#sendmail-tip').html('<i class="layui-icon layui-icon-loading-1 layui-anim layui-anim-rotate layui-anim-loop"></i> {$tran.please_wait} ...');
            data.field.content = layedit.getContent(lay_content);
            $.post('{$site_url}/{$lang}/admin/sendmail.html', data.field, function (res) {
                $('#sendmail-tip').html('');
                if (res.code) {
                    if (res.code == '1') return layer.alert(res.msg, { title: '{$tran.info}', icon: 2, btn: ['{$tran.ok}'] });
                    return $('#sendmail-tip').html('<i class="layui-icon layui-icon-close"></i> ' + res.msg);
                }
                layer.alert(res.msg, { title: '{$tran.info}', icon: 1, btn: ['{$tran.ok}'] }, function (index) {
                    layer.close(index);
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }, "json");
            return false;
        });
    });
</script>

{include file='admin/footer.html'}